package com.lw.common.web.util;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lw.common.constant.LogConstant;

/**
 * @author wei.liu
 * @version 2016年5月20日 下午3:44:45
 */
public final class LoginHelper {
	private static Logger logger = LoggerFactory.getLogger(LoginHelper.class);

	private LoginHelper() {
	}

	/** 用户登录 */
	public static final Boolean login(String account, String password) {
		UsernamePasswordToken token = new UsernamePasswordToken(account, password);
		token.setRememberMe(true);
		Subject currentUser = SecurityUtils.getSubject();
		logger.info(LogConstant.LOG_MARK + currentUser.getSession().getId());
		currentUser.login(token);
		return currentUser.isAuthenticated();
	}

	/** 用户 退出 */
	public static final Boolean logout() {
		Subject currentUser = SecurityUtils.getSubject();
		currentUser.logout();
		return currentUser.isAuthenticated();
	}
}
